ReadMe
======

### HOW TO RUN THIS CODE WITH R
In order to run this script you can either 
1) open the R Console 
2) type after the prompt 
   source(file.choose()) 
3) select the file "replication.R"

or
1) from any Unix-like shell type 
2) at the prompt type

   R CMD BATCH --vanilla --slave replication.R &

### THE OUTPUT

The result of the script will be a series of figures in pdf format which have been used in the manuscript to show the examples:
+ fig1-bw.pdf
+ fig1-col.pdf
+ fig2-bw.pdf
+ fig2-col.pdf

a series of .rda files which contain the partial calculation of the analysis:
+ all.rda
+ cem.rda
+ mdm.rda
+ psm.rda

and Table 1 in the manuscript in LaTeX format:
+ table1.tex


### WHICH ADDITIONAL PACKAGES ARE NEEDED

In order to run the R code you need to use the latest version of R and cem package and the additional packages listed below:
* cem      (to be installed from CRAN)
* cluster  (included in the basic R distribution)
* MatchIt  (to be installed from CRAN)
* Matching (to be installed from CRAN)
* xtable   (to be installed from CRAN)

To install a package within R type, e.g. for CEM,

install.packages("cem")

### HOW WE RUN THIS CODE FOR THE MANUSCRIPT

This replication script have been tested under these conditions:
# R version 3.4.4 (2018-03-15)
# CEM package Version: 1.1.17
and 
# cluster v. 2.0.6
# MatchIt v. 3.0.2
# Matchit v. 4.9-12
# xtable  v. 1.8-2

The overall running time should be less than 3 minuts. In seconds it is:
   user  system elapsed 
143.022  11.173 156.924 

Hardware:
OS:  OSX v. 10.12.6
CPU: 3,5 GHz Intel Core i7
RAM: 16 GB


